package com.bookcode.service;


//import com.bookcode.dao.CourseRepository;
import com.bookcode.dao.StudentRepository;
import com.bookcode.entity.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class StudentService {

    @Autowired
    StudentRepository studentRepository;

    /**
     *
     * 查询学生信息
     */
//    @Autowired
//    CourseRepository courseRepository;
    //根据id 选择学生
    public Student findStudentById(Long id){
        return studentRepository.findById(id).get();
    }
    //根据姓名选择学生
    public Student findStudentByName(String name){
        return studentRepository.findStudentByName(name);
    }
    //选择所有学生
    public List<Student> findAll(){
        return studentRepository.findAll();
    }

    //根据学号查找学生
    public Student findStudentByXuehao(String xuehao){
        return studentRepository.getStudentByXuehao(xuehao);
    }

    //根据用户名查找学生
    public Student findStudentByUsername(String username){
        return studentRepository.getStudentByUsename(username);
    }

    /**
     *
     * 增加
     */
    public void save(Student student){
        studentRepository.save(student);

    }

    /**
     *
     * 通过学生学号删除学生
     */
    public void deleteStudentByXuehao(String xuehao) {
        studentRepository.deleteStudentByXuehao(xuehao);
    }
    //通过id删除学生
    public void deleteStudentById(Long id){
        studentRepository.deleteById(id);
    }
}
